#### II Replication ####
### purpose: replicating table C1 ####
# installing packages ----

list.of.packages = c('estimatr', 'stargazer', 'MASS')
new.packages <- list.of.packages[!(list.of.packages %in% 
                                     installed.packages()[,"Package"])]

if(length(new.packages)) install.packages(new.packages)

# loading packages ----

suppressPackageStartupMessages(
  {
    library(estimatr)
    library(stargazer)
    library(MASS)
  }
)

# loading in data ----
vote_res <- readRDS("~/data/rep_data3_rollcall.RDS")

voteres1 <- glm(pro_vote_novoting0 ~ modi0_num_firm + as.factor(file), data=vote_res, family = binomial("logit"))

voteres2 <- glm(pro_vote_novoting0 ~ modi0_num_firm+ 
                  highskill + highedu + 
                  medianincome + unemploy + 
                  black + white + hispanic + foreignborn
                +  EvanProt + Catholic + MainProt
                + app + foreign  + 
                  labor + corp + bank + prezSupport 
                + as.factor(state) + as.factor(file) , data = vote_res, 
                family = binomial("logit"))


voteres3 <- glm(pro_vote_novoting0 ~ modi0_num_firm+ 
                  highskill + highedu + 
                  medianincome + unemploy + 
                  black + white + hispanic + foreignborn
                +  EvanProt + Catholic + MainProt
                + nominate1 + app + foreign  + 
                  labor + corp + bank + prezSupport 
                + as.factor(state) + as.factor(file) , data = vote_res, 
                family = binomial("logit"))

stargazer(voteres1, voteres2, voteres3,
          model.names =TRUE,
          header=FALSE,
          keep=c("modi0_num_firm", 
                 "highskill", "highedu",
                 "medianincome", "unemploy",
                 "black", "white", "hispanic",
                 "foreignborn",
                 "EvanProt","Catholic", "MainProt",
                 "nominate1", "app", "foreign", 
                 "labor", "corp", "bank",
                 "prezSupport"),
          covariate.labels=c("DevFirm Num",
                             "HighSkill", 
                             "HighEdu",
                             " ln(MedianIncome)", 
                             "Unemploy", 
                             "Black", 
                             "White", 
                             "Hispanic", 
                             "ForeignBorn",
                             "EvanProt", 
                             "Catholic",  
                             "MainProt", 
                             "Nominate1",
                             "ApproprtnCommt",
                             "ForeignCommt", 
                             "LaborPAC", 
                             "CorpPAC", 
                             "BankPAC",
                             "PrezSupport"), 
          align=T,
          font.size="scriptsize",
          omit.stat=c("f", "ser", "bic", "aic", "ll", "theta"),
          column.sep.width="0pt",
          dep.var.labels = "Dependent Variable: Roll-Call Vote (Yea = 1, Nay = 0)",
          title = "Results for Hypothesis 1 (with Roll-Call Vote Data)", 
          omit.table.layout="l",
          type="latex",
          add.lines = list( c("state FE", "N", "Y",  "Y"), 
                            c("bill FE", "N",  "Y", "Y")))